package apps

import "gitee.com/zatto/project/tree/master/vblog/api/logger"

var internalAppStore = map[string]IocObject{}

type IocObject interface {
	Name() string
	Init() error
}

func Registry(obj IocObject) {
	// 判断对象是否注册
	if _, ok := internalAppStore[obj.Name()]; ok {
		panic(obj.Name() + " has registied")
	}

	// 存入appStore
	internalAppStore[obj.Name()] = obj

	// 打印日志
	logger.L().Debug().Msgf("object %s registried", obj.Name())
}

func GetInternalApp(objName string) any {
	if v, ok := internalAppStore[objName]; ok {
		return v
	}
	panic(objName + " not found")
}
